<?php 

header('Content-type: image/png'); 

$colors = array(
    array( 237, 125, 69 ),
    array( 196, 181, 173 ),
    array( 163, 100, 11 ),
    array( 247, 55, 55 ),
    array( 102, 115, 250 ),
    array( 70, 232, 172 ),
    array( 133, 245, 81 ),
    array( 242, 208, 73 ),
    array( 222, 120, 250 ),
    array( 237, 88, 167 ),
);
$darkcolors = array(
    array( 196, 101, 53 ),
    array( 163, 151, 145 ),
    array( 133, 80, 7 ),
    array( 179, 35, 35 ),
    array( 70, 79, 179 ),
    array( 43, 166, 120 ),
    array( 90, 171, 50 ),
    array( 199, 164, 35 ),
    array( 174, 86, 200 ),
    array( 201, 52, 132 )
);

$handle = imagecreate(200, 200); 
$background = imagecolorallocate($handle, 255, 255, 255); 

$votes = $_GET[ 'votes' ];
$total = array_sum( $votes );

for ( $centerY = 110; $centerY >= 100; --$centerY ) {
    $end = 0;
    foreach ( $votes as $i => $vote ) {
        if ( $vote == 0 ) {
            continue;
        }
        $start = $end; // this starts from where previous ended
        $end = $start + round( 360 * $vote / $total );
        $c = $centerY > 100 ? $darkcolors[ $i ] : $colors[ $i ];
        $color = imagecolorallocate( $handle, $c[ 0 ], $c[ 1 ], $c[ 2 ] );
        imagefilledarc( $handle, 100, $centerY, 200, 100, $start, $end, $color, IMG_ARC_PIE );
    }
}

imagepng($handle); 

?>
